package com.linko.intelligent.remote.core.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.linko.intelligent.common.util.HttpUtil;
import com.linko.intelligent.remote.core.mapper.IotLatLngMapper;
import com.linko.intelligent.remote.core.mapper.IotStatusMapper;
import com.linko.intelligent.remote.core.service.IotService;
import com.linko.intelligent.remote.pojo.po.Ioco;
import com.linko.intelligent.remote.pojo.po.IotLatLng;
import com.linko.intelligent.remote.pojo.query.IotQuery;
import com.linko.intelligent.remote.pojo.vo.PositionReportVo;
import com.linko.intelligent.remote.pojo.vo.SpeedReportVo;
import com.linko.intelligent.remote.pojo.vo.StopReportVo;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class IotServiceImpl implements IotService {
    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(HttpUtil.class);

    @Value("${url.dj92}")
    private String apiUrl;

    @Autowired
    private IotLatLngMapper iotLatLngMapper;

    @Autowired
    private IotStatusMapper iotStatusMapper;


    @Override
    public PageInfo<IotLatLng> positionList(IotQuery query) {
        PageInfo<IotLatLng> pageInfo = PageHelper.startPage(query.getPn(), query.getPs()).doSelectPageInfo(
                () -> iotLatLngMapper.selectAll(query)
        );
        return pageInfo;
    }

    @Override
    public PageInfo<StopReportVo> countStopList(IotQuery query) {
        PageInfo<StopReportVo> pageInfo = PageHelper.startPage(query.getPn(), query.getPs()).doSelectPageInfo(
                () -> iotStatusMapper.countStop(query)
        );
        return pageInfo;
    }

    @Override
    public PageInfo<SpeedReportVo> countSpeed(IotQuery query) {
        PageInfo<SpeedReportVo> pageInfo = PageHelper.startPage(query.getPn(), query.getPs()).doSelectPageInfo(
                () -> iotStatusMapper.countSpeed(query)
        );
        return pageInfo;
    }

    @Override
    public PageInfo<PositionReportVo> positionDetailList(IotQuery query) {
        PageInfo<PositionReportVo> pageInfo = PageHelper.startPage(query.getPn(), query.getPs()).doSelectPageInfo(
                () -> iotLatLngMapper.positionDetailList(query)
        );
        return pageInfo;
    }

    @Override
    public PageInfo<Ioco> iocoPage(IotQuery query) {
        PageInfo<Ioco> pageInfo = PageHelper.startPage(query.getPn(), query.getPs()).doSelectPageInfo(
                () -> iotLatLngMapper.selectAllWithStatus(query)
        );
        return pageInfo;
    }
}


